<?php
/**
 * Created by PhpStorm.
 * User: 丶晓
 * Date: 2017/8/24
 * Time: 15:50
 */

namespace app\home\service;

use app\common\Base;
use app\home\model\AccountModel;

class AccountService extends AccountModel
{
    /*
     *  根据 miniID 查询单次数据
     *  return false;
     */
    public function getminiAppsData($type, $miniID)
    {  // Session : login_miniID
        switch ($type) {
            case 'appid':
                return $this->selectInfo('seleteWXOPEN_id', $miniID);
                break;
            case 'secret':
                return $this->selectInfo('seleteWXOPEN_secret', $miniID);
                break;
        }
        return false;
    }

    /*
     *  同步登陆到微擎 https://Cloud.suyongw.com 中
     */
    public static function login_we7($username, $password)
    {
        $token = AccountService::we7_token($username, $password);
        $content = Base::_requestPost('https://cloud.suyongw.com/web/index.php?c=user&a=login', ['username' => $username, 'password' => $password, 'token' => $token], false, false, false, true);
        list($header, $body) = explode("\r\n\r\n", $content);
        preg_match("/set\-cookie:([^\r\n]*)/i", $body, $matches);
        return ['content' => $header, 'cookies' => $matches];
    }

    public static function we7_token($username, $password)
    {
        return md5($username . date('Y-m-d h') . $password);
    }
}